// This is a basic Flutter widget test.
//
// To perform an interaction with a widget in your test, use the WidgetTester
// utility in the flutter_test package. For example, you can send tap and scroll
// gestures. You can also use WidgetTester to find child widgets in the widget
// tree, read text, and verify that the values of widget properties are correct.

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:qilo/main.dart';
import 'package:qilo/core/services/data_persistence_manager.dart';

void main() {
  testWidgets('App starts and shows splash screen', (
    WidgetTester tester,
  ) async {
    // 创建数据持久化管理器实例
    final dataPersistenceManager = DataPersistenceManager();
    await dataPersistenceManager.init();

    // Build our app and trigger a frame.
    await tester.pumpWidget(
      MyApp(dataPersistenceManager: dataPersistenceManager),
    );

    // 验证应用启动
    expect(find.byType(MyApp), findsOneWidget);

    // 等待一帧渲染
    await tester.pump();

    // 验证启动页面存在
    expect(find.text('qilo App'), findsOneWidget);
  });

  testWidgets('Counter increments in home page', (WidgetTester tester) async {
    // 创建数据持久化管理器实例
    final dataPersistenceManager = DataPersistenceManager();
    await dataPersistenceManager.init();

    // Build our app and trigger a frame.
    await tester.pumpWidget(
      MyApp(dataPersistenceManager: dataPersistenceManager),
    );

    // 等待启动页面完成
    await tester.pump(const Duration(seconds: 4));

    // 查找计数器
    expect(find.text('0'), findsOneWidget);

    // 点击增加按钮
    await tester.tap(find.text('点击增加'));
    await tester.pump();

    // 验证计数器增加
    expect(find.text('1'), findsOneWidget);
  });
}
